package com.medicine.hbp.adapter;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.medicine.hbp.base.MyBaseAdapter;
import com.medicine.hbp.mob.TheDiseaseTypesVo;
import com.medicine.hbp.mob.messageListVo;
import com.medicine.hbp.ui.ArtMeActivity;
import com.medicine.hbp.R;

public class TheDiseaseTypesAdapter extends BaseAdapter {
	private LayoutInflater inflater;
	private Activity activity;
	private List<TheDiseaseTypesVo> data=new ArrayList<TheDiseaseTypesVo>();
	public TheDiseaseTypesAdapter(Activity activity) {
		this.activity = activity;
		inflater = LayoutInflater.from(activity);
	}
	public void setItems(List<TheDiseaseTypesVo> data){
		this.data=data;
		notifyDataSetChanged();
	}
	@Override
	public int getCount() {
		return data.size();
	}
	public String getid(){
		String id = "";
		for (int i = 0; i < data.size(); i++) {
			if(data.get(i).isSubscribe==1){
				id+=data.get(i).bLaberId+",";
			}
		}
		if(TextUtils.isEmpty(id)){
			id="";
		}else{
			id=id.substring(0, id.length()-1);
		}
		return id;

	}
	@Override
	public Object getItem(int arg0) {
		return arg0;
	}
	@Override
	public long getItemId(int arg0) {
		return arg0;
	}
	@Override
	public View getView(final int position, View view, ViewGroup arg2) {
		ViewHolder holder = null;
		if (view == null) {
			holder = new ViewHolder();
			view = inflater.inflate(R.layout.item_thediseasetypes, null);
			holder.name = (TextView) view.findViewById(R.id.name);
			holder.renshu = (TextView) view.findViewById(R.id.renshu);
			holder.dywz = (TextView) view.findViewById(R.id.dywz);
			holder.dy_img = (ImageView) view.findViewById(R.id.dy_img);
			view.setTag(holder);
		} else {
			holder = (ViewHolder) view.getTag();
		}
		final TheDiseaseTypesVo vo = data.get(position);
		if (vo != null) {
			holder.name.setText(vo.bLaberName);
			holder.renshu.setText(vo.bLaberSaveNumber+"人订阅");
			if(vo.isSubscribe==1){//已订阅
				holder.dywz.setText("已订");
				holder.dywz.setTextColor(activity.getResources().getColor(R.color.color_209DFD));
				holder.dy_img.setImageResource(R.mipmap.optiondiseasekindschecked);
			}else{//未订阅
				holder.dywz.setText("订阅");
				holder.dy_img.setImageResource(R.mipmap.optiondiseasekinds);
				holder.dywz.setTextColor(activity.getResources().getColor(R.color.color_7F7F7F));
			}
		}
		view.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
				if(vo.isSubscribe==1){//已订阅
					data.get(position).isSubscribe=0;
				}else{//未订阅
					data.get(position).isSubscribe=1;
				}
				notifyDataSetChanged();
			}
		});
		return view;
	}

	class ViewHolder {
		TextView name;
		TextView renshu;
		ImageView dy_img;
		TextView dywz;

	}

}
